package com.fs.alert.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.alert.domain.po.Detection;
import com.fs.alert.mapper.DetectionMapper;
import com.fs.alert.service.IDetectionService;
import com.fs.common.domain.PageVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class DetectionServiceImpl extends ServiceImpl<DetectionMapper, Detection> implements IDetectionService {
    private final DetectionMapper detectionMapper;
    @Override
    public PageVO<Detection> getDetectionsByAlertId(Long alertId, int pageNum, int pageSize) {
        Page<Detection> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Detection> wrapper = Wrappers.<Detection>lambdaQuery();
        wrapper.eq(Detection::getAlertId, alertId);
        wrapper.orderByDesc(Detection::getDetectionTime);

        return PageVO.of(detectionMapper.selectPage(page, wrapper), detection -> detection);
    }
}
